home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / MOUSE.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  9KB  |  342 lines

  1. .I 0 339
  2. /*
  3. ** A series of routines to provide access to MicroSoft (and compatible)
  4. ** mice.  Consult your mouse documentation for detailed information regarding
  5. ** each mouse driver function.
  6. **
  7. ** by Bob Jarvis w/ modifications by Bob Stout
  8. */
  9.  
  10. #include <dos.h>
  11. #include "mouse.h"
  12.  
  13. int mouse_present = 0;  /* globally visible */
  14.  
  15. /*
  16. ** Uses driver function 0 to initialize the mouse software to its default
  17. ** settings.  If no mouse is present it returns 0.  If a mouse is present, it
  18. ** returns -1, and places the value of the mouse type (2 = MicroSoft,
  19. ** 3 = Mouse Systems, other values are possible) in *mousetype.  Also
  20. ** initializes the global variable mouse_present (0 = no mouse, !0 = mouse
  21. ** is available).
  22. */
  23.  
  24. int ms_reset(int *mousetype)
  25. {
  26.       union REGS workregs;
  27.  
  28.       workregs.x.ax = 0;
  29.       int86(MSMOUSE,&workregs,&workregs);
  30.       *mousetype = workregs.x.bx;
  31.       mouse_present = workregs.x.ax;
  32.       return(mouse_present);
  33. }
  34.  
  35. /*
  36. ** Makes the mouse cursor visible.
  37. */
  38.  
  39. void ms_show_cursor(void)
  40. {
  41.       union REGS workregs;
  42.  
  43.       workregs.x.ax = 1;
  44.       int86(MSMOUSE,&workregs,&workregs);
  45. }
  46.  
  47. /*
  48. ** Hides the mouse cursor.  Should be called before changing any portion of
  49. ** the screen under the mouse cursor.
  50. */
  51.  
  52. void ms_hide_cursor(void)
  53. {
  54.       union REGS workregs;
  55.  
  56.       workregs.x.ax = 2;
  57.       int86(MSMOUSE,&workregs,&workregs);
  58. }
  59.  
  60. /*
  61. ** Obtains information about the mouse position and button status.
  62. ** Places the current horizontal and vertical positions in *horizpos and
  63. ** *vertpos, respectively.  Returns the mouse button status, which is
  64. ** mapped at the bit level as follows:
  65. **    Bit 0 - left button    \
  66. **    Bit 1 - right button    >-- 0 = button up, 1 = button down
  67. **    Bit 2 - middle button  /
  68. */
  69.  
  70. int ms_get_mouse_pos(int *horizpos, int *vertpos) /* Returns button status */
  71. {
  72.       union REGS workregs;
  73.  
  74.       workregs.x.ax = 3;
  75.       int86(MSMOUSE,&workregs,&workregs);
  76.       *horizpos = workregs.x.cx;
  77.       *vertpos  = workregs.x.dx;
  78.       return(workregs.x.bx);
  79. }
  80.  
  81. /*
  82. ** Moves the mouse cursor to a new position.
  83. */
  84.  
  85. void ms_set_mouse_pos(int horizpos, int vertpos)
  86. {
  87.       union REGS workregs;
  88.  
  89.       workregs.x.ax = 4;
  90.       workregs.x.cx = horizpos;
  91.       workregs.x.dx = vertpos;
  92.       int86(MSMOUSE,&workregs,&workregs);
  93. }
  94.  
  95. /*
  96. ** Obtains information about the last time the specified button
  97. ** (0 = left, 1 = right, 2 = middle) was pressed.  Returns the current
  98. ** button status (same format as return from ms_get_mouse_pos() above).
  99. */
  100.  
  101. int ms_button_press_status(int  button,
  102.                            int *press_count,
  103.                            int *column,
  104.                            int *row)
  105. {
  106.       union REGS workregs;
  107.  
  108.       workregs.x.ax = 5;
  109.       workregs.x.bx = button;
  110.       int86(MSMOUSE,&workregs,&workregs);
  111.       *press_count = workregs.x.bx;
  112.       *column = workregs.x.cx;
  113.       *row = workregs.x.dx;
  114.       return(workregs.x.ax);
  115. }
  116.  
  117. /*
  118. ** Similar to above but obtains information about the last release of the
  119. ** specified button.
  120. */
  121.  
  122. int ms_button_release_status(int  button,
  123.                              int *release_count,
  124.                              int *column,
  125.                              int *row)
  126. {
  127.       union REGS workregs;
  128.  
  129.       workregs.x.ax = 6;
  130.       workregs.x.bx = button;
  131.       int86(MSMOUSE,&workregs,&workregs);
  132.       *release_count = workregs.x.bx;
  133.       *column = workregs.x.cx;
  134.       *row = workregs.x.dx;
  135.       return(workregs.x.ax);
  136. }
  137.  
  138. /*
  139. ** Forces the mouse cursor to remain within the range specified.
  140. */
  141.  
  142. void ms_restrict_horiz(int min, int max)
  143. {
  144.       union REGS workregs;
  145.  
  146.       workregs.x.ax = 7;
  147.       workregs.x.cx = min;
  148.       workregs.x.dx = max;
  149.       int86(MSMOUSE,&workregs,&workregs);
  150. }
  151.  
  152. /*
  153. ** Forces the mouse cursor to remain within the range specified.
  154. */
  155.  
  156. void ms_restrict_vert(int min, int max)
  157. {
  158.       union REGS workregs;
  159.  
  160.       workregs.x.ax = 8;
  161.       workregs.x.cx = min;
  162.       workregs.x.dx = max;
  163.       int86(MSMOUSE,&workregs,&workregs);
  164. }
  165.  
  166. void ms_define_window(int left, int top, int right, int bottom)
  167. {
  168.       ms_restrict_horiz(left,right);
  169.       ms_restrict_vert(top,bottom);
  170. }
  171.  
  172. /*
  173. ** Allows the user to set the graphics cursor to a new shape.  Check your
  174. ** mouse reference manual for full information about the use of this function.
  175. */
  176.  
  177. void ms_set_graphics_cursor(int      horiz_hotspot,
  178.                             int      vert_hotspot,
  179.                             unsigned seg_shape_tables,
  180.                             unsigned offset_shape_tables)
  181. {
  182.       union REGS workregs;
  183.       struct SREGS segregs;
  184.  
  185.       workregs.x.ax = 9;
  186.       workregs.x.bx = horiz_hotspot;
  187.       workregs.x.cx = vert_hotspot;
  188.       workregs.x.dx = offset_shape_tables;
  189.       segregs.es  = seg_shape_tables;
  190.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  191. }
  192.  
  193. /*
  194. ** Selects either the software or hardware cursor and sets the start and stop
  195. ** scan lines (for the hardware cursor) or the screen and cursor masks (for
  196. ** the software cursor).  Consult your mouse reference for more information.
  197. */
  198.  
  199. void ms_set_text_cursor(int type, int screen_mask, int cursor_mask)
  200. {
  201.       union REGS workregs;
  202.  
  203.       workregs.x.ax = 10;
  204.       workregs.x.bx = type;
  205.       workregs.x.cx = screen_mask;
  206.       workregs.x.dx = cursor_mask;
  207.       int86(MSMOUSE,&workregs,&workregs);
  208. }
  209.  
  210. /*
  211. ** Obtains the horizontal and vertical raw motion counts since the last
  212. ** request.
  213. */
  214.  
  215. void ms_read_motion_counters(int *horiz, int *vert)
  216. {
  217.       union REGS workregs;
  218.  
  219.       workregs.x.ax = 11;
  220.       int86(MSMOUSE,&workregs,&workregs);
  221.       *horiz = workregs.x.cx;
  222.       *vert  = workregs.x.dx;
  223. }
  224.  
  225. /*
  226. ** Sets up a subroutine to be called when a given event occurs.
  227. ** NOTE: Use with extreme care.  The function whose address is provided MUST
  228. **    terminate with a far return (i.e. must be compiled using large model).
  229. **    Also, no DOS or BIOS services may be used, as the user-defined function
  230. **    is (in effect) an extension to an interrupt service routine.
  231. */
  232.  
  233. void ms_set_event_subroutine(int      mask,
  234.                              unsigned seg_routine,
  235.                              unsigned offset_routine)
  236. {
  237.       union REGS workregs;
  238.       struct SREGS segregs;
  239.  
  240.       workregs.x.ax = 12;
  241.       workregs.x.cx = mask;
  242.       workregs.x.dx = offset_routine;
  243.       segregs.es  = seg_routine;
  244.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  245. }
  246.  
  247. /*
  248. ** Turns light pen emulation mode on.
  249. */
  250.  
  251. void ms_light_pen_on(void)
  252. {
  253.       union REGS workregs;
  254.  
  255.       workregs.x.ax = 13;
  256.       int86(MSMOUSE,&workregs,&workregs);
  257. }
  258.  
  259. /*
  260. ** turns light pen emulation mode off.
  261. */
  262.  
  263. void ms_light_pen_off(void)
  264. {
  265.       union REGS workregs;
  266.  
  267.       workregs.x.ax = 14;
  268.       int86(MSMOUSE,&workregs,&workregs);
  269. }
  270.  
  271. /*
  272. ** Sets the sensitivity of the mouse.  Defaults are 8 and 16 for horizontal
  273. ** and vertical sensitivity (respectively).
  274. */
  275.  
  276. void ms_set_sensitivity(int horiz, int vert)
  277. {
  278.       union REGS workregs;
  279.  
  280.       workregs.x.ax = 15;
  281.       workregs.x.cx = horiz;
  282.       workregs.x.dx = vert;
  283.       int86(MSMOUSE,&workregs,&workregs);
  284. }
  285.  
  286. /*
  287. ** Sets up a region of the screen inside of which the mouse cursor will
  288. ** automatically be 'hidden'.
  289. */
  290.  
  291. void ms_protect_area(int left, int top, int right, int bottom)
  292. {
  293.       union REGS workregs;
  294.  
  295.       workregs.x.ax = 16;
  296.       workregs.x.cx = left;
  297.       workregs.x.dx = top;
  298.       workregs.x.si = right;
  299.       workregs.x.di = bottom;
  300.       int86(MSMOUSE,&workregs,&workregs);
  301. }
  302.  
  303. /*
  304. * Similar to ms_set_graphics_cursor() but allows a larger cursor.  Consult
  305. ** your mouse documentation for information on how to use this function.
  306. */
  307.  
  308. int ms_set_large_graphics_cursor(int      width,
  309.                                  int      height,
  310.                                  int      horiz_hotspot,
  311.                                  int      vert_hotspot,
  312.                                  unsigned seg_shape_tables,
  313.                                  unsigned offset_shape_tables)
  314. {
  315.       union REGS workregs;
  316.       struct SREGS segregs;
  317.  
  318.       workregs.x.ax = 18;
  319.       workregs.x.bx = (width << 8) + horiz_hotspot;
  320.       workregs.x.cx = (height << 8) + vert_hotspot;
  321.       workregs.x.dx = offset_shape_tables;
  322.       segregs.es  = seg_shape_tables;
  323.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  324.       if(workregs.x.ax == -1)
  325.             return(workregs.x.ax); /* Return -1 if function 18 supported */
  326.       else  return(0);             /* else return 0                      */
  327. }
  328.  
  329. /*
  330. ** Sets the threshold value for doubling cursor motion.  Default value is 64.
  331. */
  332.  
  333. void ms_set_doublespeed_threshold(int speed)
  334. {
  335.       union REGS workregs;
  336.  
  337.       workregs.x.ax = 19;
  338.       workregs.x.dx = speed;
  339.       int86(MSMOUSE,&workregs,&workregs);
  340. }
  341. .D 1 85
  342.